﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Net.Http.Formatting;
//using System.Xml.Linq;
//using System.Net.Http.Headers;
//using System.IO;

//namespace HPCloud.Objects.DataAccess.Compute
//{
//    public class KeyPairMediaTypeFormatter : MediaTypeFormatter
//    {
//        public KeyPairMediaTypeFormatter()
//        {
//            this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml"));
//        }
//        protected override void OnWriteToStream(Type type, object value, System.IO.Stream stream, System.Net.Http.Headers.HttpContentHeaders contentHeaders, System.Net.TransportContext context)
//        {
            
//        }
//        protected override object OnReadFromStream(Type type, System.IO.Stream stream, System.Net.Http.Headers.HttpContentHeaders contentHeaders)
//        {

//            stream.Seek(0, System.IO.SeekOrigin.Begin);
//            StreamReader rdr = new StreamReader(stream);
//            string str = rdr.ReadToEnd();

//            //str.Replace("<keypair>" +  Environment.NewLine + "        " + "<keypair>" + Environment.NewLine, "<keypair>");
//            str.Replace("<keypair>" + Environment.NewLine, "<keypairyo>");
            
//           var instance = Activator.CreateInstance(type);

//           XDocument doc = XDocument.Load(stream);
//           //doc.Elements
//          // XElement request = XElement.Load(stream);

//           IEnumerable<XElement> elements = doc.Root.Descendants("name");
//           //IEnumerable<XNode> elements2 = doc.DescendantNodes();

//         //  IEnumerable<XNode> elements = request.DescendantNodes().Where(n => n.Parent.Name == "keypair"); //.Select(w => w.NextNode).SelectMany();

//           return null;


//        //    +		Name	{{http://docs.openstack.org/compute/api/v1.1}keypair}	System.Xml.Linq.XName

    

//              //////var links = xml.Elements("link");

//              //////Console.WriteLine("links count: " + links.Count());

//              //////var linksList = new List<Link>();

//              ////// foreach (var link in links)

//              ////// {

//              //////   linksList.Add(new Link { Rel = link.Attribute("rel").Value, HRef = link.Attribute("href").Value });

//              //////}

//              //////type.GetProperty("Links").SetValue(instance, linksList, null);

    

//              //////// Now set the rest of the properties

//              ////// foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty))

//              ////// {

//              //////    Console.WriteLine("setting property: " + property.Name);

//              //////     type.SetPropertyValue(property.Name, xml.Element(property.Name), instance);

//              ////// }

    

//              //////  return instance;
//        }
//    }
//}
